<?php

/**
 * 微商城模块定义
 *
 * @author WeEngine Team
 * @url
 */
defined('IN_IA') or exit('Access Denied');

class Ewei_shoppingModule extends WeModule {
	public function fieldsFormDisplay($rid = 0) {
		global $_W;
		$setting = $this->module['config'];
		include $this->template('rule');
	}

	public function fieldsFormSubmit($rid = 0) {
		global $_GPC, $_W;
		if (!empty($_GPC['title'])) {
			$data = array(
				'title' => safe_gpc_string($_GPC['title']),
				'description' => safe_gpc_string($_GPC['description']),
				'picurl' => $_GPC['picurl'],
				'url' => create_url('mobile/module/list', array('name' => 'shopping', 'weid' => $_W['weid'])),
			);
			$this->saveSettings($data);
		}
		return true;
	}

	public function settingsDisplay($settings) {
		global $_GPC, $_W;

		if (checksubmit()) {
			$cfg = array(
				'noticeemail' => $_GPC['noticeemail'],
				'mobile' => $_GPC['mobile'],
				'shopname' => $_GPC['shopname'],
				'template' => $_GPC['template'],
				'templateid' => $_GPC['templateid'],
				'address' => $_GPC['address'],
				'phone' => $_GPC['phone'],
				'officialweb' => $_GPC['officialweb'],
				'status' => intval($_GPC['status']),
				'description' => $_GPC['description']
			);
			$cfg['description'] = preg_replace('/&lt;img\s.*?style=&quot;.*?&quot;.*?/', '<img style="width: 100%"', $cfg['description']);
			$cfg['description'] = htmlspecialchars_decode($cfg['description']);
			if (!empty($_GPC['logo'])) {
				$cfg['logo'] = $_GPC['logo'];
			}
			if ($this->saveSettings($cfg)) {
				message('保存成功', 'refresh');
			}
		}
		load()->func('tpl');
		include $this->template('setting');
	}
}
